package org.jeecg.modules.basicParts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.modules.basicParts.entity.BasicParts;
import org.jeecg.modules.basicParts.mapper.BasicPartsMapper;
import org.jeecg.modules.basicParts.service.IBasicPartsService;
import org.jeecg.modules.basicProducts.entity.BasicProducts;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description: 部品
 * @Author: jeecg-boot
 * @Date:   2025-01-07
 * @Version: V1.0
 */
@Service
public class BasicPartsServiceImpl extends ServiceImpl<BasicPartsMapper, BasicParts> implements IBasicPartsService {

    @Override
    public BasicParts getByPartsSku(String sku) {
        LambdaQueryWrapper<BasicParts> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BasicParts::getPartsSku, sku);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public BasicParts getByPartsBack(String back) {
        LambdaQueryWrapper<BasicParts> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BasicParts::getPartsBack, back);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public Map<String, BasicParts> getByPartsSkus(Set<String> partsSkus) {
        LambdaQueryWrapper<BasicParts> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(BasicParts::getPartsSku, partsSkus);
        List<BasicParts> basicProductsList = list(wrapper);

        Map<String, BasicParts> basicProductsMap = new HashMap<>();
        for (BasicParts basicProduct : basicProductsList) {
            basicProductsMap.put(basicProduct.getPartsSku(), basicProduct);
        }
        return basicProductsMap;
    }

}
